<?php
/**
 * This is the model class for table "{{transaksi}}".
 *
 * The followings are the available columns in table '{{transaksi}}':
 * @property integer $id
 * @property integer $id_jenis
 * @property integer $id_status
 * @property string $pekerjaan
 * @property string $rekanan
 * @property integer $tahap
 * @property string $periode_awal
 * @property string $periode_akhir
 * @property string $kurs
 * @property double $nilai
 * @property double $nilai_rupiah
 *
 * The followings are the available model relations:
 * @property TransaksiJenis $idJenis
 * @property TransaksiStatus $idStatus
 * @property TransaksiAtribut[] $transaksiAtributs
 * @property TransaksiKeteranganGagal[] $transaksiKeteranganGagals
 * @property TransaksiOperasi[] $transaksiOperasis
 * @property TransaksiSki[] $transaksiSkis
 */
class Transaksi extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @return Transaksi the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return '{{transaksi}}';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('id_status, pekerjaan, rekanan, kurs, nilai, nilai_rupiah', 'required'),
			array('id_jenis, id_status, tahap', 'numerical', 'integerOnly'=>true),
			array('periode_awal, periode_akhir', 'date', 'format'=>'yyyy-MM-dd'),
			array('periode_akhir', 'compare', 'compareAttribute' => 'periode_awal', 'operator' => '>'),
			array('nilai, nilai_rupiah', 'numerical'),
			array('pekerjaan', 'length', 'max'=>120),
			array('rekanan', 'length', 'max'=>60),
			array('kurs', 'length', 'max'=>6),
			array('periode_awal, periode_akhir', 'safe'),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('id, id_jenis, id_status, pekerjaan, rekanan, tahap, periode_awal, periode_akhir, kurs, nilai, nilai_rupiah', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'idJenis' => array(self::BELONGS_TO, 'TransaksiJenis', 'id_jenis'),
			'idStatus' => array(self::BELONGS_TO, 'TransaksiStatus', 'id_status'),
			'transaksiAtributs' => array(self::HAS_ONE, 'TransaksiAtribut', 'id_transaksi'),
			'transaksiKeteranganGagals' => array(self::HAS_ONE, 'TransaksiKeteranganGagal', 'id_transaksi'),
			'transaksiOperasis' => array(self::HAS_ONE, 'TransaksiOperasi', 'id_transaksi'),
			'transaksiSkis' => array(self::HAS_ONE, 'TransaksiSki', 'id_transaksi'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'id_jenis' => 'Id Jenis',
			'id_status' => 'Status',
			'pekerjaan' => 'Pekerjaan',
			'rekanan' => 'Rekanan',
			'tahap' => 'Tahap',
			'periode_awal' => 'Periode Awal',
			'periode_akhir' => 'Periode Akhir',
			'kurs' => 'Kurs',
			'nilai' => 'Nilai',
			'nilai_rupiah' => 'Nilai Rupiah',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id);
		$criteria->compare('id_jenis',$this->id_jenis);
		$criteria->compare('id_status',$this->id_status);
		$criteria->compare('pekerjaan',$this->pekerjaan,true);
		$criteria->compare('rekanan',$this->rekanan,true);
		$criteria->compare('tahap',$this->tahap);
		$criteria->compare('periode_awal',$this->periode_awal,true);
		$criteria->compare('periode_akhir',$this->periode_akhir,true);
		$criteria->compare('kurs',$this->kurs,true);
		$criteria->compare('nilai',$this->nilai);
		$criteria->compare('nilai_rupiah',$this->nilai_rupiah);

		return new CActiveDataProvider(get_class($this), array(
			'criteria'=>$criteria,
		));
	}
}